{include file="header/index" /}
<div class="newContentBox">

    <form class="layui-form newListPart" id="myform" enctype="multipart/form-data">
        <input type="hidden" id="id" value="{$id}">
        <div class="newPart">
            <!-- 基本信息 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">基本信息</span>
                <a class="newBtnDefault newBtnGray" onclick="returnBack(this)"> <i class="fa fa-mail-reply"></i>返回</a>
            </div>
            <div class="newContent">
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">姓名：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="worker_name" type="text" name="workers_name" value="" placeholder="请输入姓名" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">身份证：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="workers_id_card" value="" placeholder="请输入身份证号码" onKeyUp="value=value.replace(/[\W]/g,'')"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">员工编号：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="workers_number" type="text" name="workers_number" value="" placeholder="请输入员工编号" readonly="readonly"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">电话号码：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" id="tel" type="text" name="workers_phone" placeholder="请输入电话号码" onkeyup="this.value=this.value.replace(/\D/g,'')"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">生日：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input newDate cover_date" id="birthday" type="text" name="birthday" placeholder="请选择生日"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">入职时间：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input newDate cover_date" id="workers_entry_time" type="text" name="workers_entry_time" placeholder="请选择入职时间"/>
                        <i class="label_right_text">注：该时间将作为计算考核的开始时间</i>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">业绩标准：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="inspection_standard" value="" placeholder="请输入业绩标准"/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">完成业绩：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="inspection_results" value="" placeholder="请输入完成业绩" readonly/>
                    </div>
                </div>
<!--                <div class="layui-form-item cover_layui_f_i">-->
<!--                    <label class="layui-form-label cover_layui_f_l">是否合格：</label>-->
<!--                    <div class="layui-input-block cover_layui_i_b">-->
<!--                        <select name="select" id="check_out" class="cover_layui_s">-->
<!--                            <option value="1">合格</option>-->
<!--                            <option value="0">不合格</option>-->
<!--                        </select>-->
<!--                    </div>-->
<!--                </div>-->
            </div>

            <!-- 账户信息 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">账户信息</span>
                <div>
                    {if condition="isset($editMoney) && $editMoney"}
                    <a class="layui-btn newBtnDefault" id="editAcount" onclick="editAcount()">修改金额</a>
                    {/if}
                    <a href='{:url("Employee/fundsRecord")}?id={$id}' class="newBtnDefault">账户记录</a>
                </div>
            </div>
            <div class="newContent">
<!--                <div class="layui-form-item cover_layui_f_i">-->
<!--                    <label class="layui-form-label cover_layui_f_l">总金额：</label>-->
<!--                    <div class="layui-input-block cover_layui_i_b">-->
<!--                        <input class="layui-input" type="text" name="total_money" value="" placeholder="请输入总金额" readonly/>-->
<!--                        <i class="label_right_text">注：总金额=可提现金额+已提现金额</i>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">可提现金额：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="cash_available" value="" placeholder="请输入可提现金额" readonly/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">已提现金额：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="already_present_money" value="" placeholder="请输入已提现金额" readonly/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">冻结金额：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="temp_money" value="" placeholder="请输入冻结金额" readonly/>
                    </div>
                </div>
            </div>

            <!-- 其他信息 -->
            <div class="newTitleBox">
                <span class="layui-inline newListTitle">其他信息</span>
                <a href='{:url("Employee/structure")}?id={$id}' class="newBtnDefault">查看团队</a>
            </div>
            <div class="newContent">
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">推[姓名]：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="invite_name" value="" placeholder="请输入推荐人姓名" readonly/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">推[编号]：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="invite_number" value="" placeholder="请输入推荐人编号" readonly/>
                    </div>
                </div>
                <div class="layui-form-item cover_layui_f_i">
                    <label class="layui-form-label cover_layui_f_l">推[电话]：</label>
                    <div class="layui-input-block cover_layui_i_b">
                        <input class="layui-input" type="text" name="invite_phone" value="" placeholder="请输入推荐人电话" readonly/>
                    </div>
                </div>
            </div>

            <div class="layui-form-item ">
                <div class="layui-input-block cover_layui_i_b">
                    <a class="layui-btn newBtnDefault" onclick="javascript:history.go(-1);">取消</a>
                    {if condition="isset($edit) && $edit"}
                    <a class="layui-btn newBtnDefault newBtnPrimary" id="btn">编辑</a>
                    {/if}
                </div>
            </div>
        </div>

    </form>

</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl;
    $.ajaxSetup({headers: {token: $.cookie('token'),company: $.cookie('company_id')}});;
    // 时间日期选择
    $('#birthday').each(function(){
        laydate.render({
            elem: this,
        })
    })
    $('#workers_entry_time').each(function(){
        laydate.render({
            elem: this,
        })
    })

    Ajaxdata();
    function Ajaxdata(){
        var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
        var request_data = {};
        request_data.id = $("#id").val();
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Dealer/dealerInfo",request_data,function (flag) {
            layer.close(loadingFlag);
            if (flag.code < 0){
                layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                return false;
            }
            $("input[name='workers_name']").val(flag.data.workers_name);
            $("input[name='workers_id_card']").val(flag.data.workers_id_card);
            $("input[name='workers_number']").val(flag.data.workers_number);
            $("input[name='workers_phone']").val(flag.data.workers_phone);

            if (flag.data.workers_birthday != 0){
                $("input[name='birthday']").val(flag.data.workers_birthday);
            }else {
                var date = "";
                if(flag.data.workers_id_card.length == 15) {
                    date =  '19'+flag.data.workers_id_card.substr(6,2)+'-'+flag.data.workers_id_card.substr(8,2)+'-'+flag.data.workers_id_card.substr(10,2);
                } else if (flag.data.workers_id_card.length == 18) {
                    date =  flag.data.workers_id_card.substr(6,4)+'-'+flag.data.workers_id_card.substr(10,2)+'-'+flag.data.workers_id_card.substr(12,2);
                }
                $("input[name='birthday']").val(date);
            }
            if (flag.data.workers_entry_time != 0){
                $("input[name='workers_entry_time']").val(flag.data.workers_entry_time);
            }
            $("input[name='inspection_standard']").val(flag.data.inspection_standard);
            $("input[name='inspection_results']").val(flag.data.inspection_results);
            //$("#check_out").val(flag.data.check_out);
            $("input[name='total_money']").val(flag.data.total_money);
            $("input[name='cash_available']").val(flag.data.cash_available);
            $("input[name='already_present_money']").val(flag.data.already_present_money);
            $("input[name='temp_money']").val(flag.data.temp_money);
            $("input[name='invite_name']").val(flag.data.invite_name);
            $("input[name='invite_number']").val(flag.data.invite_number);
            $("input[name='invite_phone']").val(flag.data.invite_phone);
        });
    }

    //账户修改
    function editAcount() {
        // var total_money = $("input[name='total_money']").val();
        // var cash_available = $("input[name='cash_available']").val();
        // var commissions = $("input[name='commissions']").val();

        var html = '';
        html +='<form class="layui-form popBox" action="#" method="post">';
        /*
        html +='<div class="popChoose">';
        html +='<div class="leftPop">总金额：</div>';
        html +='<div class="rightPop">';
        html +='<input class="layui-input" type="text" name="Etotal_money" placeholder="增加或减少总金额" id="total_money" value=""/>';
        html +='</div>';
        html +='</div>';
        */
        html +='<div class="popChoose">';
        html +='<div class="leftPop">可提现金额：</div>';
        html +='<div class="rightPop">';
        html +='<input class="layui-input" type="text" name="Ecash_available" placeholder="增加或减少可提现金额" id="cash_available" value=""/>';
        html +='</div>';
        html +='</div>';
        html +='<div class="popChoose">';
        html +='<div class="leftPop">冻结金额：</div>';
        html +='<div class="rightPop">';
        html +='<input class="layui-input" type="text" name="Ecommissions" placeholder="增加或减少提成金额"  id="commissions" value=""/>';
        html +='</div>';
        html +='</div>';
        html +='<div class="popChoose">';
        html +='<div class="leftPop">备注：</div>';
        html +='<div class="rightPop">';
        html +='<textarea placeholder="请输入备注" rows="2" class="layui-textarea" id="remarks"></textarea>';
        html +='</div>';
        html +='</div>';
        html +='</form>';
        parent.layer.open({
            title:'账户信息修改',
            type: 6,
            area: ['500px', '450px'], //宽高
            shadeClose: false, //点击遮罩关闭
            content: html,
            btn: ['确认', '取消'],
            btnAlign: 'c'
            ,success:function(){
                parent.form.render();
            }
            ,yes: function(index, layero){
                var request_data = {};
                request_data.id = $("#id").val();
                //request_data.total_money = $(layero).find("#total_money").val();
                request_data.cash_available = $(layero).find("#cash_available").val();
                request_data.commissions = $(layero).find("#commissions").val();
                request_data.note = $(layero).find("#remarks").val();
                request_data = JSON.stringify(request_data);
                $.post("{:config('api')}/Achievement/Dealer/editMoney",request_data,function (flag) {
                    parent.layer.close(index);
                    if (flag.code < 0){
                        layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                        return false;
                    }
                    layer.msg(flag.message,{icon:1,time:1500,shade: 0.1,});
                    window.location.reload();
                })
            }
            ,btn2: function(index, layero) {
                //按钮【按钮二】的回调
                // return false;//开启该代码可禁止点击该按钮关闭// return true;
            }
            ,cancel: function(){
                //右上角关闭回调
                // return false; //开启该代码可禁止点击该按钮关闭
            }
        });
    }
    //提交表单
    $("#btn").click(function () {
        var workers_name = $("input[name='workers_name']").val();
        var workers_id_card = $("input[name='workers_id_card']").val();
        var workers_phone = $("input[name='workers_phone']").val();
        var birthday = $("input[name='birthday']").val();
        var workers_entry_time = $("input[name='workers_entry_time']").val();
        var inspection_standard = $("input[name='inspection_standard']").val();
        var check_out = $("#check_out option:selected").val();

        if (workers_name.length == 0){
            top.layer.msg('请输入姓名', {icon: 2});
            return false;
        }
        if (workers_id_card.length == 0){
            top.layer.msg('请输入身份证', {icon: 2});
            return false;
        }
        if (workers_phone.length == 0){
            top.layer.msg('请输入电话', {icon: 2});
            return false;
        }
        if (workers_entry_time.length == 0){
            top.layer.msg('请选择入职时间', {icon: 2});
            return false;
        }
        if (inspection_standard.length == 0){
            top.layer.msg('请输入业绩标准', {icon: 2});
            return false;
        }
        var index = layer.load(1, {
            shade: [0.1,'#fff'] //0.1透明度的白色背景
        });
        var request_data = {};
        request_data.workers_id = $("#id").val();
        request_data.workers_name = workers_name;
        request_data.workers_phone = workers_phone;
        request_data.workers_id_card = workers_id_card;
        request_data.workers_entry_time = workers_entry_time;
        request_data.workers_birthday = birthday;
        request_data.inspection_standard = inspection_standard;
        request_data.check_out = check_out;
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Dealer/editDealer",request_data,function (flag) {
            layer.close(index);
            if (flag.code < 0){
                layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                return false;
            }
            layer.msg(flag.message,{icon:1,time:1500,shade: 0.1,});
            window.location.reload();
        })
    });

    $(function(){
        // 焦点事件验证数据是否为空
        $("input[name='workers_name']").blur(function(){
            var workers_name = $("input[name='workers_name']").val();
            if (workers_name == '') {
                top.layer.msg('姓名不能为空', {icon: 2});
                return false;
            }
        });
        $("input[name='workers_id_card']").blur(function(){
            var workers_id_card = $("input[name='workers_id_card']").val();
            if (workers_id_card == '') {
                top.layer.msg('身份证号码不能为空', {icon: 2});
                return false;
            }
        });
        $("input[name='workers_password']").blur(function(){
            var workers_password = $("input[name='workers_password']").val();
            if (workers_password == '') {
                top.layer.msg('密码不能为空', {icon: 2});
                return false;
            }
        });
        $("input[name='workers_phone']").blur(function(){
            var workers_phone = $("input[name='workers_phone']").val();
            if (workers_phone == '') {
                top.layer.msg('电话号码不能为空', {icon: 2});
                return false;
            }
        });

    })
</script>
